define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {
                 shop_id:0,
                 items:[],

                 type:1
                };
            },
            el: '#pageBook',
            created: function() {
                this.fetchData();
            },
              mounted: function() {
                    
                    if (this.mounted == 1) {
                        return;
                    }
                    
                this.mounted = 1;
            },

            methods: {
                fetchData: function() {
                    var _this = this;

                    this.shop_id = this.$route.params.shop_id;
 
                     this.getList();
                   
                },
                getList:function(){
                  var that = this ;
                     that.loading = 1;
                     
                    app.get("mall/dining_table/get", {
                      shop_id :  this.shop_id,
                       order:'id desc',
                    }, function (res) {
                      that.loading = 0;
                      if (res.code != 200) {
                         app.alert(res.msg);
                         return ;
                      }
                      that.items = res.data.list; 
                    });
                },
                preview:function(){
                  var user_info = app.getUserInfo();
                  var  url = "/pages/book/?store_id="+user_info.store_id+"#/";
                  window.location.href = url;
                   
                },
                pageShow:function(){
                   var reload= app.getPageData("index",'reload');
                   // console.log(reload);
                   if(reload){
                     app.setPageData("index",{reload:0});
                     this.getList();
                   }
                    
                },
                delBook:function(id){
                   var that = this;
                    app.confirm({
                     'text':'确认删除吗？',
                     'yes':function(){
                        app.get("mall/dining_table/del",{id:id,shop_id:this.shop_id},function(res){
                            if(res.code!=200){
                               app.alert(res.msg);
                               return ;
                            }
                            that.getList();
                        });
                     }
                  });
                },
                shareUrl:function(){
                  var store_id = app.getStoreId();
                  var  url = "/apps/?app=book&store_id="+store_id+"#/";
                  var shareUrl = encodeURIComponent("https://wap.bestsmartbee.com"+url);
                  this.$router.push({name:"shareUrl",params:{url:shareUrl}});

                }
            }

        }).$mount('#app');
    };
    module.exports = controller;
});
